﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using HandyControl.Controls;

namespace AgileLogistics.View.Cailiao.CURD
{
    /// <summary>
    /// CreatePage.xaml 的交互逻辑
    /// </summary>
    public partial class CreatePage : Page
    {
        ViewModel.MaterialViewModel vm;
        Model.DBContext context = new Model.DBContext();
        public CreatePage()
        {
            InitializeComponent();

            vm = DataContext as ViewModel.MaterialViewModel;

            vm.CurrentMaterial = new Model.Materials();
        }

        private void btn_cancel_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btn_Save_Click(object sender, RoutedEventArgs e)
        {
            if(string.IsNullOrEmpty( vm.CurrentMaterial.ItemName) )
            {
                Growl.WarningGlobal("请输入材料名称！");
                return;
            }
            if ( vm.CurrentMaterial.ItemCount <=0 )
            {
                Growl.WarningGlobal("请输入数量！");
                return;
            }

            context.DB.Insertable<Model.Materials>(vm.CurrentMaterial).ExecuteCommand();
            Growl.SuccessGlobal("保存成功！");
        }
    }
}
